import {
	Component
} from 'react';
import {
	Tab,
	Button,
	ScrollList,
	Group,
	Boxs,
	Avatar,
	Badge,
	Popup,
	Dialog,
	Toast,
	SearchBar
} from 'saltui';
const {
	IconButton,
	ButtonGroup
} = Button;
const {
	HBox,
	Box,
	VBox
} = Boxs;

import {
	urlPrefix,
	URLS,
	nodataIcon,
	dictMap
} from '../../../app/variables';
import AngleRight from 'salt-icon/lib/AngleRight';
import DB from '../../../app/db';
import PostPageItem from 'components/post_page_item';

let tabPage = '0';
export default class PageHome extends Component {

	constructor(props) {
		super(props);
		var hasBottomTab =  document.getElementById("hasBottomTab").value;
		let winHeight =  getScrollHigh(1, 0, 0);
		var context = document.getElementById("context").value;
		this.state = {
			winHeight: winHeight,
			addClickAble:false,
			activeTabIndex:tabPage,
			search: {title:''},
			urlPrev: context + '/api/m/plugin/attachment/mobile/viewImage?fid=',
			noDataTip:"暂无数据",
		}

		dd.biz.navigation.setTitle({
      		title: "审核帖子",
		    onSuccess: function (result) {
		    },
     		 onFail: function () {
      		}
    		});

		this.searchBarProps = {
			placeholder: "请输入标题",
			instantSearch: false,
			hasHistory: false,
			searchDelay: 450,
			exitAfterEnter: false,
			onEnter: () => {
				//console.log('enter');
			},
			onExit: this.onExit.bind(this),
			onChange: (value) => {
				//console.log(`Typing>>${value}`);
			},
			onSearch: this.onSearch.bind(this)
		};
		

}

	/*componentWillMount() {
		this.getPhoto();
	}*/
	componentDidMount() {
		window.scrollTo(0,0);

		 //获取首页信息
		 let t = this;
		 t.searchBarLimit('30');
	}
	/*componentWillUnmount(){

	}*/

	searchBarLimit(len){
		$(".t-search-bar-input").attr('maxlength',len);
	}

	beforeFetch(data, form) {
		this.setState({
			addClickAble:false,
		});
		data.type="0";
		data.title=this.state.search.title;
		return data;
	}

	onExit() {
		this.onSearch1("");	
	}

	onSearch1(value) {
		let param = this.state.search;
		param.title=value;
		this.flushData(param,tabPage);
		this.setState({
			noDataTip:"暂无数据"
		});
	}


	

	onSearch(value) {
		this.setState({
			noDataTip:"无搜索结果"
		});
		let param = this.state.search;
		param.title=value;
    	this.flushData(param,tabPage);
	}

	onRefresh(value) {
		let param = this.state.search;
		param.title=value;
    	this.flushData(param,tabPage);
		/*if (this.state.search) {
			let search = {};
			search['\'CN_title\''] = value;
			this.flushData({
				search
			});
		}*/
	}

	flushData(param, index) {
		this.flushCheckData(param);
	}

	flushCheckData(param) {
		this.refs.forum_my_check_ref.fetchData(param);
	}

	changeClickAble(){
		this.setState({
			addClickAble:true,
		});
	}

	processData(data) {
		this.setState({
			addClickAble:true,
		});
		return data;
	}

	
	

	render() {
		let winHeightStyle = {
			height:this.state.winHeight
		};
		return (
		<div>
			<SearchBar ref="search_forum_my_check_ref" {...this.searchBarProps} />
	            <div style={winHeightStyle}>
	              	<ScrollList
		               className=""
		               url={URLS.checkMyPost}
		               dataType="json"
		               pageSize={10}
		               beforeFetch={this.beforeFetch.bind(this)}
		               processData={this.processData.bind(this)}
		               onRefresh={this.onRefresh.bind(this)}
		               ref = 'forum_my_check_ref'
					   noDataImage={nodataIcon}
					   noDataTip={this.state.noDataTip}
		               currentPageKey="page"
		              >
					  <PostPageItem pagetype="myCheck" addClickAble={this.state.addClickAble} changeClickAble={this.changeClickAble.bind(this)} isShowCount={false}  flushData={this.flushCheckData.bind(this)} />
             		</ScrollList>
             	</div>
          </div>
		);
	}
}